package com.nus.iss.ad.dbhelper;

import java.util.Arrays;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.nus.iss.ad.model.CollectionPoint;
import com.nus.iss.ad.utils.JsonParser;
import com.nus.iss.ad.utils.MyConfig;

public class CollectionPointDBHelper {
	
	
	public List<CollectionPoint> getAllCollectionPoints() {
		
		 String url=MyConfig.BACKEND_PATH + "/api/getAllCollectionPoints";
	     //url=url+"/"+poId;
	     
	     
		 JSONArray json=JsonParser.getJSONArrayFromUrl(url);
		 CollectionPoint data = new CollectionPoint();
		 CollectionPoint[] collectionPoints=null;

		 try {
			 JSONArray jsonOrderDetailArray=json;
			 
			 collectionPoints=new CollectionPoint[jsonOrderDetailArray.length()];
			 
		 for(int i=0;i<jsonOrderDetailArray.length();i++){
			 JSONObject o=jsonOrderDetailArray.getJSONObject(i);
			 
			 CollectionPoint c = new CollectionPoint();
			 
			 c.setCollectionId(o.getInt("collectionPtId"));
			 c.setDescription(o.getString("Description"));
			 
			 collectionPoints[i] = c;
		 }
		 } catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		 return Arrays.asList(collectionPoints);
		
	}

}
